require 'rubygems'
require 'test/unit'
require 'mocha'
require 'agent_interface'
class TestAgentInterface < Test::Unit::TestCase
  def setup
    @agent = stub_everything()
    @path = '/path/to/file'
    @shared_file = stub_everything()
  end
  
  def test_all_files_published
    s_interface = mock()
    s_interface.expects(:publish).times(3)
    @agent.expects(:server_interface).returns(s_interface)
    agent_interface = AgentInterface.new(@agent, [1,2,3])
    agent_interface.publish_to_server
  end

  def test_we_can_find_a_particular_file
    @shared_file.expects(:path).at_least_once.returns(@path)
    interface = AgentInterface.new(@agent, [@shared_file, stub_everything()])
    file = interface.find_file(@path)
    assert_equal(@path, file.path)
  end

  def test_we_can_update_contents_of_a_file
    @shared_file.expects(:path).at_least_once.returns(@path)
    interface = AgentInterface.new(@agent, [@shared_file])
    content = "new content"
    @shared_file.expects(:content=).with(content)
    interface.update_file(@path, content)
  end

  def test_update_non_existant_file_raises_exception
    begin
      interface = AgentInterface.new(@agent, [])
      interface.update_file(@path, "")
      fail("should get exception")
    rescue
    end
  end
end
